from django.db import models
from article.models import Article


# Create your models here.

class User(models.Model):
    """
    前台用户模型
    """
    username = models.CharField(verbose_name="用户名称", max_length=100, unique=True, default="Jack")
    email = models.EmailField(verbose_name="邮箱")
    password = models.CharField(verbose_name="密码", max_length=32)
    register_time = models.DateTimeField(verbose_name="注册时间", auto_now_add=True)

    class Meta:
        db_table = "tb_user"
        verbose_name = "用户"
        verbose_name_plural = verbose_name


class Record(models.Model):
    """
    会员搜索记录表
    """
    user = models.ForeignKey(to=User, on_delete=models.CASCADE)
    search = models.CharField(max_length=500, verbose_name="搜索记录")
    add_time = models.DateTimeField(verbose_name="添加时间", auto_now_add=True)

    class Meta:
        db_table = "tb_record"
        verbose_name = "会员搜索记录"
        verbose_name_plural = verbose_name


class Comments(models.Model):
    content = models.CharField(max_length=500, verbose_name="评论内容")
    user = models.ForeignKey(to=User, on_delete=models.CASCADE, verbose_name="评论者")
    article = models.ForeignKey(to=Article, on_delete=models.CASCADE, verbose_name="评论的文章")
    comment_time = models.DateTimeField(verbose_name="评论的时间", auto_now_add=True)

    class Meta:
        db_table = "tb_comments"
        verbose_name = "文章评论"
        verbose_name_plural = verbose_name



